﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.Ctrls;
using CommunitySystem.Views;
using CommunitySystem.Assert;
using EHR.Common;
using System.Windows.Browser;

namespace CommunitySystem
{
    public partial class IndexControl : AsyncCtrl, IReturnListenerc
    {
        public static event EventHandler Logout;
        private SystemService.SystemServiceClient client = new SystemService.SystemServiceClient();
        public IndexControl()
        {
            InitializeComponent();
       
            client.GetCommunitySysteLoginTimeCompleted += new EventHandler<SystemService.GetCommunitySysteLoginTimeCompletedEventArgs>(client_GetCommunitySysteLoginTimeCompleted);
            client.GetCommunitySysteLoginTimeAsync(Session.LoginUser.LoginName);
        }
        void client_GetCommunitySysteLoginTimeCompleted(object sender, SystemService.GetCommunitySysteLoginTimeCompletedEventArgs e)
        {
            var list = e.Result;
            if (list.Count > 1)
            {
                tbtoday.Visibility = System.Windows.Visibility.Visible;
                tbTotal.Visibility = System.Windows.Visibility.Visible;
                TodayCount.Visibility = System.Windows.Visibility.Visible;
                totalCount.Visibility = System.Windows.Visibility.Visible;
                totalCount.Text = list[1] + "";
                TodayCount.Text = list[0] + "";
            }
        }
        public void BeginReturn()
        {
           
        }

        /// <summary>
        /// 加载时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            App._FlipSwitch = flipSwitch;
            tbUserName.Text = Session.LoginUser.RealName;

            object obj = Activator.CreateInstance(Type.GetType("CommunitySystem.Views.大图标.TBControl"));
            obj.GetType().GetProperty("Nav").SetValue(obj, new NavMoveSwitch() { FirstPage = obj as FrameworkElement }, null);
            flipSwitch.SetNewPage(obj as CommunitySystem.Views.IAsyncCtrl, obj.GetType().GetProperty("Nav").GetValue(obj, null) as NavMoveSwitch);
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbExit_Click(object sender, MouseButtonEventArgs e)
        {
            if (Logout != null)
            {
                Logout(this, EventArgs.Empty);
            }
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UPPass_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            UpdatePasswordWindow Up = new UpdatePasswordWindow();
            Up.Show();

            Up.Closed += new EventHandler(Up_Closed);
        }

        /// <summary>
        /// 提示修改成功
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Up_Closed(object sender, EventArgs e)
        {
            UpdatePasswordWindow DDItem = (UpdatePasswordWindow)sender;
            if (DDItem.DialogResult == true)
            {
                SilverlightMessageBoxLibrary.Message.InfoMessage("修改成功！");
            }

        }

     
    }
}
